﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-09-15 17:39:04
 * 功能：
**************************************************************************************/

using DG.Tweening;
using System;
using UnityEngine;
using UnityEngine.UI;

namespace Game.UI.PreviewPanel
{
    public class Item : MonoBehaviour
    {
        private RectTransform m_Rect;
        private Image m_Icon;

        private void Awake()
        {
            m_Rect = transform as RectTransform;
            m_Icon = transform.Find("Border/Mask/Icon").GetComponent<Image>();
        }

        public void SetPos(Vector2 pos, bool isShowAnim)
        {
            if (isShowAnim)
                m_Rect.DOAnchorPos(pos, 0.5f).SetEase(Ease.OutBack);
            else
                m_Rect.anchoredPosition = pos;
        }

        public void Init(Sprite data)
        {
            m_Icon.sprite = data;
            var size = UIUtility.CalcSizeToFill(m_Icon.transform.parent.parent as RectTransform, m_Icon.sprite.texture);
            m_Icon.rectTransform.sizeDelta = new Vector2(size.width, size.height);
        }
    }
}